/**
 * @package: BrickCAD
 * @className: FrontView.java
 * @package: default
 * @author: Sean O'Brien, Jack , Lester Tam, Erik Telstad
 * @date_created: November 16, 2009
 * @last_motified: November 16, 2009
 * 
 * 
 * 
 */


import java.awt.*;
import java.util.Observable;

public class FrontView extends BrickView {

	private static final long serialVersionUID = 1L;
	private static String title = "Front View";
	static int openFrameCount = 0;
	static final int xOffset = 30, yOffset = 5;
	
	private BrickImagePanel frontImage;


	/**
	 * 
	 */
	public FrontView(Brick theModel) {
		super(theModel);
		setTitle(title);
		openFrameCount++;
		setSize(300, 300);
		setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
		double x =(getX() + (getWidth()/2.0)) - (model.getLength()/2.0);
		double y =(getY() + (getHeight()/2.0)) - (model.getHeight()/2.0);
		frontImage = new BrickImagePanel(x, y, model.getLength(), model.getHeight());
		getContentPane().add(frontImage, BorderLayout.CENTER);
		add(frontImage);
	}

	/* (non-Javadoc)
	 * @see BrickView#update(java.util.Observable, java.lang.Object)
	 */
	@Override
	public void update(Observable arg0, Object o) {
		System.out.println("Updating FrontView #" + openFrameCount);
		model = (Brick) arg0;
		if(frontImage.getWidth() != model.getLength()) {
			System.out.print("Brick length: " + model.getLength());
			frontImage.setBrickWidth(model.getLength());
		}
		if(frontImage.getHeight() != model.getHeight()) {
			System.out.print("Brick height: " + model.getHeight());
			frontImage.setBrickHeight(model.getHeight());
		}	
		frontImage.repaint();
	}
}
